import java.util.Scanner;

//题目：编写一个函数，输入n为偶数时，调用函数求1/2+1/4+...+1/n,
// 当输入n为奇数时，调用函数1/1+1/3+...+1/n
public class Test39 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.println("请输入一个数:");
        int n = console.nextInt();
        double out = calculate(n);
        System.out.println("结果为:" + out);
    }

    public static double calculate(int n) {
        double out = 0;
        if (n % 2 == 0) {
            for (int i = 1; i <= n / 2; i++) {
                out += 1.0 / (2 * i);
            }
        } else {
            for (int i = 1; i <= (n + 1) / 2; i++) {
                out += 1.0 / (2 * i - 1);
            }
        }
        return out;
    }
}
